<?php
session_start();
function getlang(){
		$lang = $_SESSION['lang'];
		if (empty($lang) || $lang == "EN") {
			$value = "../value/value_en.php";
		} else if($lang == "VN") {
			$value = "../value/value_vn.php";
		}
		else {
			$value = "../value/value_kr.php";
		}
		return $value;
	}
$value = getlang();
include($value);
$listpurchase =$_SESSION['listpurchase'];
#echo $_GET['action'];
if (isset($_GET['action'])){
	if($_GET['action']=='add'){
		$listpurchase =$_SESSION['listpurchase'];
		$listpurchase[]=array(0,"","",0,0,0,0);
	}else if($_GET['action']=='del'){
		$listpurchase =$_SESSION['listpurchase'];
		$list=array();
		for($i=0;$i<count($listpurchase);$i++){	
				if($listpurchase[$i][0]==0){
					$list[]=$listpurchase[$i];
				}
		}
		$listpurchase=$list;
	}else if($_GET['action']=='check'){
		$listpurchase =$_SESSION['listpurchase'];
		$id=$_GET['id'];
		for($i=0;$i<count($listpurchase);$i++){
			if ($i==($id-1)){
				$listpurchase[$i][0]=($listpurchase[$i][0]+1)%2;
			}
		}
	}else if($_GET['action']=='chPrice'){
		$id=$_GET['id'];
		$listpurchase =$_SESSION['listpurchase'];
		for($i=0;$i<count($listpurchase);$i++){
			if ($i==($id-1)){
				$listpurchase[$i][4]=$_GET['value'];
			}
		}
	}else if($_GET['action']=='chQuantity'){
		$id=$_GET['id'];
		$listpurchase =$_SESSION['listpurchase'];
		for($i=0;$i<count($listpurchase);$i++){
			if ($i==($id-1)){
				$listpurchase[$i][3]=$_GET['value'];
			}
		}
	}else if($_GET['action']=='chName'){
		$id=$_GET['id'];
		$listpurchase =$_SESSION['listpurchase'];
		for($i=0;$i<count($listpurchase);$i++){
			if ($i==($id-1)){
				$listpurchase[$i][2]=$_GET['value'];
			}
		}
	}else if($_GET['action']=='chItem'){
		$id=$_GET['id'];
		$listpurchase =$_SESSION['listpurchase'];
		for($i=0;$i<count($listpurchase);$i++){
			if ($i==($id-1)){
				$listpurchase[$i][1]=$_GET['value'];
			}
		}
	}
}

?>

		<table class="tcontent" cellpadding="5" cellspacing="0" id="tblView"  >
			<tr class="trtit">
				<td width="3%"></td>
				<td width="3%"><?php echo $l_no?></td>
				<td width="32%"><?php echo $l_product_item?></td>
				<td width="8%"><?php echo $l_quantity?></td>
				<td width="8%"><?php echo $l_price?></td>
				<td width="8%"><?php echo $l_price_vat?></td>
				<td width="8%"><?php echo $l_total_amount?></td>
			</tr>
			
				<?php 
				$i=1;
				$total=0;
				foreach ($listpurchase as $purchase){?>
				<tr class="my_row">
					<?php if($purchase[0]==0){?>
					<td><input type="checkbox" onclick="checkPurchase(<?=$i?>)" /></td>
					<?php }else{?>
					<td><input type="checkbox" checked="checked" onclick="checkPurchase(<?=$i?>)"  /></td>
					<?php }?>
					<td><?=$i?></td>
					<td><input type="text" name="productitem[]" id='<?echo "name".$i;?>' onkeypress="return enterTable(event,this.id,<?php echo count($listpurchase);?>,'0')" onchange="chItemPurchase(this.value,<?=$i?>)" onkeyup="chItemPurchase(this.value,<?=$i?>)" style="height: 24px; width: 96%; border: 1px solid #c4c0c9" value="<?=$purchase[1]?>" /></td>
					<!--<td><input type="text" name="companyname[]" id='<?echo "company".$i;?>' onkeypress="return enterTable(event,this.id,<?php echo count($listpurchase);?>,'0')" onchange="chNamePurchase(this.value,<?=$i?>)" onkeyup="chNamePurchase(this.value,<?=$i?>)"style="height: 24px; width: 96%; border: 1px solid #c4c0c9" value="<?=$purchase[2]?>" /></td>  -->
					<td><input type="text" name="quantity[]"  id='<?echo "txtNumber".$i;?>' onkeypress="return enterTable(event,this.id,<?php echo count($listpurchase);?>,'1');" onchange="chQuantityPurchase(this.value,<?=$i?>)" onkeyup="chQuantityPurchase(this.value,<?=$i?>)" style="height: 24px; width: 96%; border: 1px solid #c4c0c9"	value="<?=$purchase[3]?>" autocomplete="off"  /></td>
					<td><div id='<?echo "price".$i;?>'><input type="text" onkeypress="return enterTable(event,this.id,<?php echo count($listpurchase);?>,'1')" id="<?echo "txtPrice".$i?>" name="price[]" onchange="chPricePurchase(this.value,<?=$i?>)"   onkeyup="chPricePurchase(this.value,<?=$i?>)" style="height: 24px; width: 96%; border: 1px solid #c4c0c9"	value="<?=$purchase[4]?>" autocomplete="off"  /></div></td>
					<td><div id='<?echo "vat".$i;?>'><input  onkeypress="return enterTable(event,this.id,<?php echo count($listpurchase);?>,'1')" id="<?echo "txtVat".$i?>" type="text" name="pricevat[]"  onchange="chVatPurchase(this.value,<?=$i?>)" onkeyup="chVatPurchase(this.value,<?=$i?>)"  style="height: 24px; width: 96%; border: 1px solid #c4c0c9"  value="<?=$purchase[5]?>" autocomplete="off"  /></div></td>
					<td><div id='<?echo "total".$i;?>'><input type="text" name="totalamount[]" style="height: 24px; width: 96%; border: 1px solid #c4c0c9"  value="<?=number_format($purchase[6])?>" readonly="readonly" /></div></td>
				</tr>
			
				
				<?php 
				$total=$total+$purchase[6];
				$i=$i+1;
				}?>
			
		</table>
	
		<table class="tcontent" cellpadding="5" cellspacing="0">
			<tr>
				<td width="20%" class="col_left"><?php echo $l_total_amount?></td>
				<td style="text-align: left">
					<div id='all'><input type="text" readonly="readonly"
					name="alltotalamount" value="<?=number_format($total)?>"
					style="height: 24px; width: 30%; border: 1px solid #c4c0c9" /></div>
				</td>
			</tr>
			<tr>
				<td class="col_left"><?php echo $l_comment?></td>
				<td><textarea rows="3" cols="5" name="comment" id="comment"
						style="width: 100%; border: 1px solid #c4c0c9"></textarea></td>
			</tr>
		</table>
<?php $_SESSION['listpurchase']=$listpurchase;?>
